<template>
  <!--<el-button type="primary" plain icon="Pointer" @click="handleAdd" style="margin-left:20px;">指定专人审核</el-button>
  <el-button type="warning" plain icon="Download" @click="handleOut">导出</el-button>-->
  <div class="home-box" style="margin-left: 70px;">
    <el-form :inline="true" :model="searchForm">
      <el-form-item label="员工姓名">
        <el-input
          v-model="searchForm.empName"
          placeholder="员工姓名"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="岗位名称">
        <el-input
          v-model="searchForm.position"
          placeholder="岗位名称"
          clearable
        ></el-input>
      </el-form-item>
	  <el-form-item label="部门名称">
	    <el-input
	      v-model="searchForm.deptName"
	      placeholder="部门名称"
	      clearable
	    ></el-input>
	  </el-form-item>
      <el-form-item>
        <el-button @click="searchEvent" type="primary">查询 </el-button>
      </el-form-item>
      <el-form-item>
        <el-button @click="update" type="primary">重置 </el-button>
      </el-form-item>
	  <el-form-item>
	  <el-button type="success" plain icon="Download" @click="handleFileAll"
	  >一键归档</el-button>
	  </el-form-item>
      <el-form-item >
        <el-tooltip class="item" effect="dark" content="刷新" placement="top">
          <el-button circle icon="Refresh" @click="update" />
        </el-tooltip>
      </el-form-item>
    </el-form>
  </div>
  <el-table 
  @selection-change="selectChange"
  :data="WaitAssessorList" style="width: 90%; margin: 20px auto;border-radius: 8px; margin: 20px auto;box-shadow: 5px 5px 10px rgba(64, 158, 255, 0.5);"
      :header-cell-style="{
          'background': '#337ecc !important',
          'color': '#ffffff',
          'border': 'none !important'
        }" size="large"
        :cell-style="{ textAlign: 'center' }">
    <el-table-column type="selection" width="55" :selection="selection" />
    <el-table-column prop="empName" label="员工姓名" width="150" >
    </el-table-column>
    <el-table-column prop="position" label="岗位" width="180"></el-table-column>
    <el-table-column prop="deptName" label="所属单元" width="120" />
    <el-table-column label="操作">
      <template #default="scope">
        <el-button 
        type="success"
         @click="wageEmpFile(scope.$index, scope.row)"
          >归档</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>


<script setup>
import {ref, onMounted,onBeforeMount, reactive} from "vue";
import { Timer } from '@element-plus/icons-vue';
import {useRouter} from "vue-router";
import {getWageFileTask,getWageFileTaskSearch} from '@/api/task'
import {file,fileAll} from '@/api/coefficient'
import { ElMessage } from 'element-plus'

const router = useRouter()
var WaitAssessorList=ref([])
onBeforeMount(()=>{
  let assessorId=JSON.parse(localStorage.getItem('userInfo')).id;
    getWageFileTask({assessorId})
    .then(data=>{
        WaitAssessorList.value=data.data;
    });
})

const selection=ref([])
const selectChange = (select) => {
  selection.value = select;
};
const handleFileAll=()=>{
  let assessorId=JSON.parse(localStorage.getItem('userInfo')).id;
  const Form=selection.value;
  fileAll({Form,assessorId}).then(data=>{
    if (data.code == 200) {
      ElMessage({
        message:"归档成功",
        type: "success",
      });
      update()
    } 
    else {
      ElMessage.error("归档失败");
    }
  })
}

const wageEmpFile =(index, row) => {
  let positionId=row.positionId;
  let empId=row.empId;
  let assessorId=JSON.parse(localStorage.getItem('userInfo')).id;
  file({positionId,empId,assessorId}).then(data=>{
    if(data.code==200){
        ElMessage({
            message: '归档成功',
            type: 'success',
        })
        update()
        }
  })
}

const update=()=>{
	
	searchForm.value.empName=""
	searchForm.value.position=""
	searchForm.value.deptName=""
	searchForm.value.assessorId=""
	
  let assessorId=JSON.parse(localStorage.getItem('userInfo')).id;
    getWageFileTask({assessorId})
    .then(data=>{
        WaitAssessorList.value=data.data;
    });
}

const searchForm = ref({
  empName: "",
  position: "",
  deptName: "",
  assessorId:""
});

const searchEvent=()=>{
  searchForm.value.assessorId=JSON.parse(localStorage.getItem('userInfo')).id;
  getWageFileTaskSearch(searchForm.value).then((data) => {
    WaitAssessorList.value = data.data;
  });
}


</script>

<style lang="scss" scoped>

</style>
